home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0058_Appending Data onto the EXE.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  122 lines

  1. {
  2. >I am trying to write a program that will extract a linked list from data
  3. >appended to the executable with the MS-Dos COPY /B command.  Is such a thing
  4. >possible?  I have been unable to do it with standard text file procedures.
  5.  
  6. You can't extract a linked list but you can retreive data and then
  7. put it into a linked list. The linked list is a memory data
  8. structure whereas the data on disk is just collections of data. You
  9. could probably do what you want with streams, though.
  10.  
  11. Here's a unit I wrote for using appended data which may help:
  12. }
  13.  
  14. unit appnddat;
  15.  
  16. (*
  17.   APPNDDAT - Copyright (c) Steve Rogers, 1994
  18.  
  19.   Allows user to store configuration data at the end of an EXE file.
  20.   The putConfig procedure stores a record at the end of the EXE file.
  21.   If data is already present in the EXE, it will be overwritten.
  22.   GetConfig will retreive data that has been appended to the EXE.
  23.  
  24.   NOTE: The pCfgRec parameter passed to both putConfig & getConfig is
  25.         a raw pointer, RecSize is the size of the config record.
  26.  
  27.         Also, since this unit gets its data from the data following
  28.         the executeable code, it won't work if you compile your EXE
  29.         in the $d+ state (include debug information).
  30. *)
  31.  
  32. (* We'll do our own i/o checking, thanks. *)
  33. {$i-}
  34.  
  35. interface
  36.  
  37. function EXESize(fname : string) : longint;
  38. function DataAppended(fname : string) : boolean;
  39. procedure putConfig(fname : string;pCfgRec : pointer;RecSize : word);
  40. procedure getConfig(fname : string;pCfgRec : pointer;RecSize : word);
  41.  
  42. implementation
  43. uses
  44.   dos;
  45.  
  46. {----------------------}
  47. function EXESize(fname : string) : longint;
  48. { Returns size of executable code in EXE file }
  49.  
  50. type
  51.   tSizeRec=record    { first 6 bytes of EXE header }
  52.     mz,
  53.     remainder,
  54.     pages : word;
  55.   end;
  56.  
  57. var
  58.   f : file of tSizeRec;
  59.   sz : tSizeRec;
  60.  
  61. begin
  62.   assign(f,fname);
  63.   reset(f);
  64.   if (ioresult<>0) then EXESize:= 0 else begin
  65.     read(f,sz);
  66.     close(f);
  67.     with sz do EXESize:= remainder+(longint(pred(pages))*512);
  68.   end;
  69. end;
  70.  
  71. {----------------------}
  72. function DataAppended(fname : string) : boolean;
  73. var
  74.   f : file;
  75.   sz : longint;
  76.  
  77. begin
  78.   assign(f,fname);
  79.   reset(f,1);
  80.   if (ioresult<>0) then DataAppended:= false else begin
  81.     sz:= filesize(f);
  82.     close(f);
  83.     DataAppended:= (sz>EXESize(fname));
  84.   end;
  85. end;
  86.  
  87. {-----------------------}
  88. procedure putConfig(fname : string;pCfgRec : pointer;RecSize : word);
  89. var
  90.   f : file;
  91.   DataOffset : longint;
  92.  
  93. begin
  94.   DataOffset:= EXESize(fname);
  95.  
  96.   assign(f,fname);
  97.   reset(f,1);
  98.   seek(f,DataOffset);
  99.   blockwrite(f,pCfgRec^,RecSize);
  100.   close(f);
  101. end;
  102.  
  103. {-----------------------}
  104. procedure getConfig(fname : string;pCfgRec : pointer;RecSize : word);
  105. var
  106.   f : file;
  107.   DataOffset : longint;
  108.  
  109. begin
  110.   if (DataAppended(fname)) then begin
  111.     DataOffset:= EXESize(fname);
  112.     assign(f,fname);
  113.     reset(f,1);
  114.     seek(f,DataOffset);
  115.     blockread(f,pCfgRec^,RecSize);
  116.     close(f);
  117.   end;
  118. end;
  119.  
  120. {----------------------}
  121. end.
  122.